﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ProgNetComponents.Validation.Rules
{
    /// <summary>
    /// Rule for checking if column is null
    /// </summary>
    public class ColumnRequiredValidationRule : ColumnValidationRule
    {
        #region Static
        /// <summary>
        /// Initializes the <see cref="ColumnRequiredValidationRule"/> class.
        /// </summary>
        static ColumnRequiredValidationRule()
        {
            GlobalDefaultErrorString = "Ta wartość jest wymagana.";
        }
        /// <summary>
        /// Gets or sets the global default error string.
        /// </summary>
        /// <value>
        /// The global default error string.
        /// </value>
        public static string GlobalDefaultErrorString { get; set; }
        #endregion

        /// <summary>
        /// Gets the default error string.
        /// </summary>
        /// <value>
        /// The default error string.
        /// </value>
        protected override string DefaultErrorString
        {
            get
            {
                    return GlobalDefaultErrorString;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ColumnRequiredValidationRule"/> class.
        /// </summary>
        public ColumnRequiredValidationRule() { }
        /// <summary>
        /// Initializes a new instance of the <see cref="ColumnRequiredValidationRule"/> class.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="error">The error.</param>
        public ColumnRequiredValidationRule(string column, string error = null)
            : base(column, error)
        {

        }

        /// <summary>
        /// Does the validate.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        protected override bool DoValidate(DataRow row)
        {
            return row.GetColumnValue(Column).IsNotNull();
        }
    }
    
}
